package com.zjitc.utils;

import sun.misc.BASE64Encoder;


import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import java.util.*;

/**
 * @author Administrator
 */
public class
Utils {
    public static String getUUID() {
        //随机生成UUID
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
        String s = encoderByMd5("1adfa");
        String s1 = encoderByMd5("1adfa");
        System.out.println(s1);
        System.out.println(s);
    }

    public static String encoderByMd5(String str)
            throws NoSuchAlgorithmException, UnsupportedEncodingException {
        //确定计算方法
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        BASE64Encoder base64en = new BASE64Encoder();
        //加密后的字符串
        String result = base64en.encode(md5.digest(str.getBytes("utf-8")));
        return result;
    }
}
